package com.weijian.dal.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * 用户状态枚举
 * 数据库中存储为整数：0-禁用，1-正常
 */
@Getter
public enum UserStatus {
    DISABLED(0, "禁用"),
    ACTIVE(1, "正常"),
    DELETED(2, "删除");

    @EnumValue
    private final int code;

    @JsonValue
    private final String description;

    UserStatus(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public static UserStatus fromCode(int code) {
        for (UserStatus status : values()) {
            if (status.code == code) {
                return status;
            }
        }
        throw new IllegalArgumentException("Invalid user status code: " + code);
    }
}